package com.atguigu.dao.impl;

import com.atguigu.bean.User;
import com.atguigu.dao.BaseDao;
import com.atguigu.dao.UserDao;

/**
 * @ Author:任留辉
 * @ Description:
 * @ Date:Created in 14:59 2021/3/10 0010
 */
public class UserDaoImpl extends BaseDao<User> implements UserDao {

    /**
     * 通过用户名和密码查询用户信息
     *
     * @param username
     * @param password
     * @return
     */
    @Override
    public User checkLogin(String username, String password) {
        String sql = "select * from ts_user where name = ? and password = ?";
        /*User user = getBean(User.class, sql,username,password);
        System.out.println(user.toString());

        return user;*/
        return getBean(User.class, sql, username, password);
    }

    /**
     * 通过用户名查询用户信息
     *
     * @param name
     * @return
     */
    @Override
    public User checkUsername(String name) {
        String sql = "select * from ts_user where name = ? ";

        return getBean(User.class, sql, name);
    }

    /**
     * 注册用户
     * @param user
     */
    @Override
    public void registUser(User user) {
        String sql = "insert into ts_user(name,password,email) values(?,?,?)";
        update(sql, user.getName(), user.getPassword(), user.getEmail());
    }
}
